Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AN/USER] 안드로이드 네비게이션을 적용한다. (#758) #781

Merged
merged 40 commits into from
Mar 13, 2024

Conversation

re4rk
Copy link
Collaborator

@re4rk re4rk commented Mar 9, 2024

📌 관련 이슈

✨ PR 세부 내용

  1. 네비게이션 2.7.7 버전으로 적용하였습니다.
  2. 팀원들이 navigation이 없어서 설명드립니다.
    • 네비게이션은 res의 navigation을 통해서 작동하게 됩니다.
    • 해당 xml이 있다면 action을 통해서 다음 프래그먼트로 이동할 수 있습니다.
    • 만약에 다음 프래그먼트에 argument 태그가 있다면 safeargs을 통해서 인자를 받게 됩니다.
findNavController().navigate(
    FestivalListFragmentDirections.actionFestivalListFragmentToArtistDetailFragment(
        artistId,
    ),
)
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/festivalList"
    app:startDestination="@id/festivalListFragment">

    <fragment
        android:id="@+id/festivalListFragment"
        android:name="com.festago.festago.presentation.ui.home.festivallist.FestivalListFragment"
        android:label="FestivalListFragment"
        tools:layout="@layout/fragment_festival_list">
        <action
            android:id="@+id/action_festivalListFragment_to_artistDetailFragment"
            app:destination="@id/artistDetailFragment"
            app:enterAnim="@android:anim/slide_in_left"
            app:popExitAnim="@android:anim/slide_out_right" />
    </fragment>
    <fragment
        android:id="@+id/artistDetailFragment"
        android:name="com.festago.festago.presentation.ui.artistdetail.ArtistDetailFragment"
        android:label="ArtistDetailFragment"
        tools:layout="@layout/fragment_artist_detail">
        <argument
            android:name="artistId"
            app:argType="long" />
    </fragment>
</navigation
  1. 바텀 네비게이션의 id들이 festivalList 처럼 변하게 되었는데 해당 id가 프래그먼트와 같아야지 동작하게 되서 변경하게 되었습니다.
       - android:id="@+id/itemFestival"
       + android:id="@+id/festivalList"
  1. 전에 톡방에서 전달 드렸던 뒤로가기 버튼을 눌렀을 때 전 화면이 리프래시 되는 현상이 있는 것을 공유 드렸습니다.
  • 해당 현상이 일어나는 이유는 navigation에서의 fragment의 생명주기가 다음과 같이 생명주기가 다시 실행되기 때문에 저희 코드에서 load를 한번 더하기 때문입니다.
스크린샷 2024-03-09 오전 10 46 44 - 따라서 다음 코드들이 추가 되었습니다. - 기존 binding이 있으면 기존꺼를 반환합니다. - 추가로 저희 화면마다 데이터를 호출하는데 refresh 플래그 값이 없으면 refresh 하지 않도록 변경했습니다. 스크린샷 2024-03-09 오전 10 48 07

EmilyCh0 and others added 30 commits February 9, 2024 23:00
# Conflicts:
#	android/festago/data/src/main/java/com/festago/festago/data/di/singletonscope/RepositoryModule.kt
#	android/festago/presentation/src/main/java/com/festago/festago/presentation/ui/home/festivallist/FestivalListFragment.kt
#	android/festago/presentation/src/main/res/drawable/ic_bookmark_normal.xml
# Conflicts:
#	android/festago/presentation/src/main/java/com/festago/festago/presentation/ui/home/festivallist/FestivalListFragment.kt
#	android/festago/presentation/src/main/java/com/festago/festago/presentation/ui/schooldetail/SchoolDetailFragment.kt
#	android/festago/presentation/src/main/res/layout/fragment_school_detail.xml
re4rk added 4 commits March 8, 2024 20:21
# Conflicts:
#	android/festago/presentation/src/main/java/com/festago/festago/presentation/ui/home/HomeActivity.kt
#	android/festago/presentation/src/main/java/com/festago/festago/presentation/ui/home/festivallist/FestivalListFragment.kt
@re4rk re4rk linked an issue Mar 9, 2024 that may be closed by this pull request
Copy link
Member

@SeongHoonC SeongHoonC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

상태바가 흰색으로 변경되게 만들었었는데 안되네요. backStack 이 변경되지 않아서 리스터가 동작하지 않습니다!

임시로 myPage 에 네비게이션 그래프를 추가해봤는데 스택이 따로 저장되네요! 이러면 fragment manager 4개로 관리할 필요는 없겠군요!

네비게이션이 생각보다 복잡하군요. 코멘트 확인해주세요!

Comment on lines 36 to 38
if (_binding == null) {
_binding = FragmentArtistDetailBinding.inflate(inflater)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

다른 화면으로 navigate 할 때 항상 onDestroyView 가 불립니다.

  • 네비게이션 action 은 무조건 replace 인가요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

null로 만들어주는게 onDestory인줄 알았는데 착각했네요
찾아보니 네비게이션 action은 무조건 replace로 작동하고
add처럼 동작하려면 dialog태그를 사용해야합니다.

Comment on lines +37 to +39
fun loadFestivalDetail(festivalId: Long, refresh: Boolean = false) {
if (!refresh && _uiState.value is FestivalDetailUiState.Success) return

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

예전에 기억이 잘 안나서 그런데
새로고침 요청이 아니고 Success 라면 서버에 재요청하지 않으려고 막은거였죠?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 initView() 호출될때마다 불필요하게 load 다시하는 거 막으려고 했던거로 기억합니당

navController =
(supportFragmentManager.findFragmentById(R.id.fcvHomeContainer) as NavHostFragment).navController
val bottomNavigationView = findViewById<BottomNavigationView>(R.id.nvHome)
bottomNavigationView.setupWithNavController(navController)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네비게이션 버튼을 클릭해서 이동할때는 괜찮은데 뒤로가기 누르면 홈에 쌓였던 것들이 초기화되네요..흠 왜 그런걸까요?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NavigationUI 내부적으로 첫번째 destination으로 popup 하게 되어있어서 그런 것 같아요.
bottom navigation menu item에 menuCategory를 secondary로 두면 탭 이동도 백스택 관리할 수 있어요! 아래 링크 참고
https://hide1202.github.io/android/navigation-backstack/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오오 감사합니다!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

베르

  • 사실 네비게이션 버튼 이동 시에 뒤로가기 누르면 홈에 쌓인 것들이 초기화 되는 것처럼 보이지만 그 상태에서 다시 홈을 누르면 홈의 스택이 다시 올라옵니다!
    해시
  • 네비게이션 전략은 다양하게 선택될 수 있을 것같은데 해시가 링크해준게 좋다고 생각해서 반영했습니다!

@SeongHoonC SeongHoonC added AN 안드로이드에 관련된 작업 USER labels Mar 9, 2024
@github-actions github-actions bot requested review from EmilyCh0 and SeongHoonC March 9, 2024 17:25
Copy link
Member

@EmilyCh0 EmilyCh0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다 👍 코멘트 확인해 주세요!

Comment on lines 41 to 43
if (_binding == null) {
_binding = FragmentFestivalDetailBinding.inflate(inflater)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

null이 아닌 게 어떤 경우인가요??

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

베르가 말해준 생명주기를 보고 롤백했습니다.

Comment on lines +37 to +39
fun loadFestivalDetail(festivalId: Long, refresh: Boolean = false) {
if (!refresh && _uiState.value is FestivalDetailUiState.Success) return

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 initView() 호출될때마다 불필요하게 load 다시하는 거 막으려고 했던거로 기억합니당

navController =
(supportFragmentManager.findFragmentById(R.id.fcvHomeContainer) as NavHostFragment).navController
val bottomNavigationView = findViewById<BottomNavigationView>(R.id.nvHome)
bottomNavigationView.setupWithNavController(navController)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NavigationUI 내부적으로 첫번째 destination으로 popup 하게 되어있어서 그런 것 같아요.
bottom navigation menu item에 menuCategory를 secondary로 두면 탭 이동도 백스택 관리할 수 있어요! 아래 링크 참고
https://hide1202.github.io/android/navigation-backstack/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 코드 제가 제거했던 것 같은데 다시 살아났네요..?

Copy link
Member

@SeongHoonC SeongHoonC Mar 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해시가 작업한 커밋이 PR에 포함되어있네요..?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

병렬 작업을 위해 해시 PR 브랜치로 타겟으로 했어요
분기 후에 코드 제거를해서 그런지 살아있는거 같네요

@@ -1,27 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/itemFestival"
android:id="@+id/festivalList"
Copy link
Member

@EmilyCh0 EmilyCh0 Mar 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@SeongHoonC SeongHoonC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

프래그먼트 정책 변경 및 버그 수정 확인했습니다!
축제 목록 to 축제 상세
animation 만 추가하고 머지합니다!

is SchoolDetailFragment,
-> false
private fun initDestinationChangedListener() {
navController.addOnDestinationChangedListener { _, destination, _ ->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addOnDestinationChangedListener 도 있군요! 또 배워갑니다!

@SeongHoonC SeongHoonC merged commit 22ca63b into dev Mar 13, 2024
1 check passed
@SeongHoonC SeongHoonC deleted the feat/#758 branch March 13, 2024 02:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AN 안드로이드에 관련된 작업 USER
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[AN] 홈 화면 네비게이션을 적용한다.
3 participants